﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net;
using Keepo.Models.Services;
using Infrastructure.Data;
using Keepo.Models;

namespace Keepo.Designer.Controllers
{
    public class ResourcesController : Controller
    {
        [HttpPost]
        public ActionResult GetDesignImageById(long imageId = 1)
        {
            return Json(DesignResourcesLogic.getDesignImageById(imageId), JsonRequestBehavior.AllowGet);
        }

        public ActionResult GetAllFonts()
        {
            return Json(DesignResourcesLogic.getAllFonts(), JsonRequestBehavior.AllowGet);
        }

        public ActionResult GetVectorCategories()
        {
            using (GenericRepository repository = new GenericRepository())
            {
                var categories = repository.GetAll<VectorCategory>();
                var anon = categories.Select(m => new { key = m.VectorCategoryId, english = m.Title, hebrew = m.TitleHebrew });
                return Json(anon.ToArray(), JsonRequestBehavior.AllowGet);
            }
        }

        [HttpPost]
        public ActionResult GetVectorsByCategoryId(int categoryId)
        {
            using (GenericRepository repository = new GenericRepository())
            {
                var vectors = repository.Find<DesignVector>(m => m.VectorCategoryId == categoryId && m.IsRemoved == false);
                var export = vectors.ToArray().Select(v => new DesignVectorExport(v));
                return Json(export);
            }
        }

        [HttpPost]
        public ActionResult GetDesignVectorById(int vectorId = 1)
        {
            return Json(DesignResourcesLogic.getDesignVectorById(vectorId), JsonRequestBehavior.AllowGet);
        }
    }
}
